#include "global.h"

#include <rclcpp/rclcpp.hpp>

namespace fusion_perception {

#define DECLARE_PARAMETER_(node, parameterEventHandler, parameterCallbackHandles, field, defaultValue) \
    node->declare_parameter(#field, defaultValue);                                                     \
    parameterCallbackHandles.emplace_back(parameterEventHandler->add_parameter_callback(#field, [this](const rclcpp::Parameter& p) { field = p.get_value<decltype(field)>(); }));

#define DECLARE_PARAMETER(field, defaultValue) DECLARE_PARAMETER_(node_, parameterEventHandler_, parameterCallbackHandles_, field, defaultValue)

Global::Global(void)
{
    node_ = std::make_shared<rclcpp::Node>("fusion_perception");

    parameterEventHandler_ = std::make_shared<rclcpp::ParameterEventHandler>(node_);

    DECLARE_PARAMETER(isRecord, isRecord);
    DECLARE_PARAMETER(hz, hz);
    DECLARE_PARAMETER(predictS, predictS);
    DECLARE_PARAMETER(Q, Q);
    DECLARE_PARAMETER(R, R);
    DECLARE_PARAMETER(dxThreshold, dxThreshold);
    DECLARE_PARAMETER(dyThreshold, dyThreshold);
    DECLARE_PARAMETER(headingThreshold, headingThreshold);
}

rclcpp::Logger Global::getLogger(void)
{
    return node_->get_logger();
}

std::shared_ptr<rclcpp::Node> Global::getNode(void)
{
    return node_;
}
}